package com.usian.user.service.impl;

import com.usian.user.mapper.UserMapper;
import com.usian.user.pojo.User;
import com.usian.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 06 26 08 44
 **/
@Service
public class UserServiceImpl implements UserService {
    final
    UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public List<User> findAllUser() {
        return userMapper.findAllUser();
    }

    @Override
    public User findUserById(Integer id) {
        return userMapper.findUserById(id);
    }

    @Override
    public User login(User user) {
        User userDb = userMapper.findUserByUserName(user);
        if(null!=userDb){
            if(userDb.getPassword().equals(user.getPassword())){
                return userDb;
            }else{
                return null;
            }
        }
        return null;
    }

    @Override
    public int save(User user) {

        return userMapper.save(user);
    }
}
